package com.example.facility.service.user;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.facility.controller.admin.user.vo.UserRespVO;
import com.example.facility.dal.dataobject.user.UserDO;
import com.example.facility.dal.mysql.UserMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户管理 Service 实现类
 *
 * @author 贵州上禾
 */
@Service
@Validated
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService {

    @Resource
    private UserMapper userMapper;


    @Override
    public List<UserRespVO> getUserList() {
        LambdaQueryWrapper<UserDO> lqw = new LambdaQueryWrapper<>();
        List<UserDO> userDOList = userMapper.selectList(lqw);
        if (CollUtil.isNotEmpty(userDOList)) {
            return userDOList.stream().map(item -> {
                UserRespVO respVO = new UserRespVO();
                respVO.setValue(item.getId());
                respVO.setLabel(item.getName());
                return respVO;
            }).collect(Collectors.toList());
        }
        return CollUtil.newArrayList();
    }
}